<?php
/**
 * Created by PhpStorm.
 * User: eppo.Wan
 * Date: 2017/11/16
 * Time: 11:02
 */
use yii\helpers\Html;
use yii\widgets\LinkPager;
use yii\helpers\Url;
?>
<div style="height:5px"></div>
<div class="btn-group" style="float: right;">
    <a href="<?=Url::toRoute(['admin/addadmin']);?>" class="btn btn-warning">添加管理员</a>
</div>
<table id="dnd-example" cellspacing="0" class="table table-striped table-hover">
    <thead>
    <tr>
        <th>ID</th>
        <th>用户名</th>
        <th>所属角色</th>
        <th class="hidden-480">最后登录IP</th>
        <th><i class="icon-time bigger-110 hidden-480"></i>最后登录时间</th>
        <th class="hidden-480">真实姓名</th>
        <th>管理操作</th>
    </tr>
    </thead>

    <?php  
        $values=$dataProvider->getModels();
        foreach($values as $value):
            $role = $roles->getRolename($value->roleid);
    ?>
    <tr id="admin_<?=$value->userid;?>">
        <td><?= Html::encode($value->userid) ?></td>
        <td><?= Html::encode($value->username) ?></td>
        <td><?= Html::encode($role['rolename']) ?></td>
        <td><?= Html::encode($value->lastloginip) ?></td>
        <td><?= $value->lastlogintime?date('Y-m-d H:i',$value->lastlogintime):'--';?></td>
        <td><?= Html::encode($value->realname) ?></td>
        <td>
            <a href="<?php echo  Url::toRoute(['admin/updateadmin', 'userid' => $value->userid,'roleid'=>$role['roleid']]);?>">
                <button type="button" class="btn btn-success">编辑</button>
            </a>
            <a onclick="del(<?=$value->userid?>)">
                <button type="button" class="btn btn-danger">删除</button>
            </a>
        </td>
    </tr>
    <?php endforeach; ?>

</table>
<?php
$pages=$dataProvider->getPagination();
echo LinkPager::widget([
    'pagination' => $pages,
]);

?>

<?php $this->beginBlock('del') ?>

//    删除栏目
    function del(userid){
        layer.confirm(
            '确定删除该管理员？',
            {icon: 5, title:'删除'},
            function(index){
                $.get("<?=Url::toRoute(['admin/deleteadmin'])?>", {userid:userid},
                    function(data){
                    if(data.status == -1){
                    $("#admin_"+userid).hide();
                }
            layer.msg(data.msg);
            });
            layer.close(index);
        });
    }
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['del'], \yii\web\View::POS_END); ?>